package com.mvc.util;

import java.lang.reflect.Field;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import com.mvc.model.ActionForm;

public class BeanUtil {

	public BeanUtil(){
		
	}
	
	public static ActionForm fixBean(HttpServletRequest request){
		ActionForm obj = null;
		try{
			String valueClass = request.getParameter("valueClass");
			if(valueClass == null)
				return null;
			Class cls = Class.forName(valueClass);
			if(cls == null)
				return null;
			obj = (ActionForm)cls.newInstance();
			Field[] fArr = cls.getDeclaredFields();
			for(Field f : fArr){
				f.setAccessible(true);
				f.set(obj, request.getParameter(f.getName()));
				f.setAccessible(false);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return obj;
	}
}
